#ifndef __WM_FWUP_H__
#define __WM_FWUP_H__

#include "wm_hal.h"

#define SIGNATURE_WORD (0xA0FFFF9FUL)
#define IMAGE_START_ADDR_MSK (0x400)

#define FLASH_OTA_FLAG_ADDR (0x80FF000UL)

typedef enum
{
	FWUP_STATUS_IDLE = 0,
	FWUP_STATUS_BUSY,
	FWUP_STATUS_ERROR,
	FWUP_STATUS_COMPLETE,
	
} FWUP_StatusDef;

typedef union
{
	struct 
	{
		uint32_t img_type: 4;
		uint32_t code_encrypt:1;
		uint32_t prikey_sel:3;
		uint32_t signature:1;
		uint32_t _reserved1:7;
		uint32_t zip_type:1;
		uint32_t psram_io:1;
		uint32_t erase_block_en:1;
		uint32_t erase_always:1;
		uint32_t _reserved2:12;
	} b;
	uint32_t w;
	
} Img_Attr_Type;

typedef struct IMAGE_HEADER_PARAM
{
	uint32_t magic_no;
	Img_Attr_Type img_attr;
	uint32_t img_addr;
	uint32_t img_len;
	uint32_t img_header_addr;
	uint32_t upgrade_img_addr;
	uint32_t org_checksum;
	uint32_t upd_no;
	uint8_t  ver[16];
	uint32_t _reserved0;
	uint32_t _reserved1;
	struct IMAGE_HEADER_PARAM *next;
	uint32_t hd_checksum;
	
} IMAGE_HEADER_PARAM_ST;

typedef struct
{
	uint32_t total_len;
	uint32_t received_len;
	uint32_t program_base;
	uint32_t program_offset;
	IMAGE_HEADER_PARAM_ST header;
	uint8_t status;
	
} FWUP_HandleTypeDef;

void HAL_FWUP_Init(FWUP_HandleTypeDef *hfwup);

HAL_StatusTypeDef HAL_FWUP_Write(FWUP_HandleTypeDef *hfwup, uint8_t *pData, uint32_t Size);

FWUP_StatusDef HAL_FWUP_Get_Status(FWUP_HandleTypeDef *hfwup);


#endif